package com.liaogui.web;

import com.liaogui.domain.AddressMap;
import com.liaogui.domain.Student;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author liaogui
 * @date 2025/1/7 10:15
 */
@RestController
@RequestMapping("/c1/")
public class TestController {
    @GetMapping("hello1")
    public void helloMVC() {
        System.out.println("hello SpringMVC！");
    }

    /**
     * http://localhost:8080/c1/param?username=liaogui&age=ff
     * @param username 用户名
     * @param age      年龄
     */
    @GetMapping("param")
    public void helloParam(@RequestParam("username") String username,
                           @RequestParam("age") String age) {
        System.out.println("userName:" + username);
        System.out.println("age:" + age);
    }


    /**
     * http://localhost:8080/c1/student?id=1&name=liaogui&address=HuNan
     * @param student 学生
     */
    @GetMapping("student")
    public void helloStudent(Student student) {
        System.out.println("student:" + student);
    }

    /**
     * 您好用户
     *
     * @param userIds 用户 ID
     */
    @GetMapping("users")
    public void helloUsers(@RequestParam String[] userIds) {
        System.out.println("userIds:" + userIds);
    }


    /**
     * 编码前：http://localhost:8080/c1/mapParam?address[one].info=bj&address[one].postcode=100010&address[two].info=sh&address[two].postcode=100011
     * 编码后：http://localhost:8080/c1/mapParam?address%5Bone%5D.info=bj&address%5Bone%5D.postcode=100010&address%5Btwo%5D.info=sh&address%5Btwo%5D.postcode=100011
     * @param addressMap 地址映射
     */
    @GetMapping("mapParam")
    public void mapParam(AddressMap addressMap) {
        System.out.println("addressMap:" + addressMap.getAddress());
    }

    /**
     * http://localhost:8080/c1/user?userName=李奥归
     * http://localhost:8080/c1/user?userName=%E6%9D%8E%E5%A5%A5%E5%BD%92
     * @param userName 用户名
     */
    @GetMapping("user")
    public void userParam(@RequestParam("userName") String userName) {
        System.out.println("userName:" + userName);
    }



}
